﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace IgnData
{
    public static class IgnConverter 
    {
        public static Point UtmToPx(Point utmPoint)
        {
            Point pxPoint = new Point();
            pxPoint.X = (utmPoint.X - 109) / 4;
            pxPoint.Y = (utmPoint.Y - 1229) / 4;
            return pxPoint;
        }

        public static Point PxToUtm(Point pxPoint)
        {
            Point utmPoint = new Point();
            utmPoint.X = 4 * pxPoint.X + 108;
            utmPoint.Y = 4 * pxPoint.Y + 1228;
            return utmPoint;
        }

        public static Point UtmToTile(Point utmPoint)
        {
            Point pxPoint = UtmToPx(utmPoint);
            Point tilePoint = new Point();
            tilePoint.X = pxPoint.X / 256;
            tilePoint.Y = (pxPoint.Y / 256) + 1;
            return tilePoint;
        }

        public static Point TileToPx(Point tilePoint)
        {
            return new Point(tilePoint.X * 256, tilePoint.Y * 256);
        }

        public static GeoCoord UtmToPx(GeoCoord utmPoint)
        {
            GeoCoord pxPoint = new GeoCoord();
            pxPoint.X = (utmPoint.X - 109) / 4;
            pxPoint.Y = (utmPoint.Y - 1229) / 4;
            return pxPoint;
        }

        public static GeoCoord PxToUtm(GeoCoord pxPoint)
        {
            GeoCoord utmPoint = new GeoCoord();
            utmPoint.X = 4 * pxPoint.X + 108;
            utmPoint.Y = 4 * pxPoint.Y + 1228;
            return utmPoint;
        }

        public static GeoCoord UtmToTile(GeoCoord utmPoint)
        {
            GeoCoord pxPoint = UtmToPx(utmPoint);
            GeoCoord tilePoint = new GeoCoord();
            tilePoint.X = pxPoint.X / 256;
            tilePoint.Y = (pxPoint.Y / 256) + 1;
            return tilePoint;
        }

        public static GeoCoord TileToPx(GeoCoord tilePoint)
        {
            GeoCoord pxPoint = new GeoCoord();
            pxPoint.X = tilePoint.X * 256;
            pxPoint.Y = tilePoint.Y * 256;
            return pxPoint;
        }
    
    
    }
}
